import { createRouter, createWebHistory } from "vue-router";
import Home from "../views/home/index.vue";

const routes = [
  {
    path: "/",
    // name: "home",
    // component: Home,
    redirect: "/index/home", // 重定向:重新指向其它path,会改变网址
  },
  {
    path: "/login",
    name: "login",
    component: () =>
      import(/* webpackChunkName: "login" */ "../views/Login.vue"),
  },
  {
    path: "/index",
    name: "index",
    component: Home,
    children: [
      {
        path: "home",
        name: "home",
        component: () =>
          import(/* webpackChunkName: "home" */ "../views/home/Home.vue"),
      },
      {
        path: "adminCar",
        name: "adminCar",
        component: () =>
          import(
            /* webpackChunkName: "adminCar" */ "../views/home/AdminCar.vue"
          ),
      },
      {
        path: "adminStation",
        name: "adminStation",
        component: () =>
          import(
            /* webpackChunkName: "adminStation" */ "../views/home/AdminStation.vue"
          ),
        children: [
          {
            path: "adminStation",
            name: "adminStation",
          },
        ],
      },
      {
        path: "adminLines",
        name: "adminLines",
        component: () =>
          import(
            /* webpackChunkName: "adminLines" */ "../views/home/AdminLines.vue"
          ),
      },
      {
        path: "adminTickets",
        name: "adminTickets",
        component: () =>
          import(
            /* webpackChunkName: "adminTickets" */ "../views/home/AdminTickets.vue"
          ),
      },
      {
        path: "adminOrder",
        name: "adminOrder",
        component: () =>
          import(
            /* webpackChunkName: "adminTickets" */ "../views/home/AdminOrder.vue"
          ),
      },
      {
        path: "orbitMonitoring",
        name: "orbitMonitoring",
        component: () =>
          import(
            /* webpackChunkName: "orbitMonitoring" */ "../views/home/OrbitMonitoring.vue"
          ),
      },
    ],
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.path == "/index/home" && !localStorage.getItem("token")) {
    next("/login");
  }
  next();
});
export default router;
